<?php

class Friendsinviter_Form_AdminServiceSettings extends Engine_Form
{
  public $saved_successfully = FALSE;

  public function init()
  {
    $settings = Engine_Api::_()->getApi('settings', 'core');
    
    $this
      ->setTitle('Service Settings')
      ->setDescription('Settings for various API Services.');

    $this->addElement('Text', 'oauth_gmail_client_id', array(
      'label' => 'Gmail Client ID',
      'description' => sprintf( $this->getTranslator()->translate('FRIENDSINVITER_FORM_ADMIN_SERVICE_GCID_DESCRIPTION'), Zend_Controller_Front::getInstance()->getRouter()->assemble(array('module' => 'friendsinviter','controller' => 'help', 'action' => 'index'), 'admin_default') . '?show=5' ),
      'value' => $settings->getSetting('friendsinviter.oauth_gmail_client_id', ''),
    ));
    $this->oauth_gmail_client_id->getDecorator('Description')->setOption('placement', 'append');
    $this->oauth_gmail_client_id->setAttrib('style', 'width:500px');
    $this->oauth_gmail_client_id->getDecorator('Description')->setOption('escape', false);

    $this->addElement('Text', 'oauth_gmail_client_secret', array(
      'label' => 'Gmail Client secret',
      'description' => sprintf( $this->getTranslator()->translate('FRIENDSINVITER_FORM_ADMIN_SERVICE_GS_DESCRIPTION'), Zend_Controller_Front::getInstance()->getRouter()->assemble(array('module' => 'friendsinviter','controller' => 'help', 'action' => 'index'), 'admin_default') . '?show=5' ),
      'value' => $settings->getSetting('friendsinviter.oauth_gmail_client_secret', '')
    ));
    $this->oauth_gmail_client_secret->getDecorator('Description')->setOption('placement', 'append');
    $this->oauth_gmail_client_secret->setAttrib('style', 'width:500px');
    $this->oauth_gmail_client_secret->getDecorator('Description')->setOption('escape', false);




    $this->addElement('Text', 'oauth_yahoo_consumer_key', array(
      'label' => 'Yahoo Consumer Key',
      'description' => sprintf( $this->getTranslator()->translate('FRIENDSINVITER_FORM_ADMIN_SERVICE_YCK_DESCRIPTION'), Zend_Controller_Front::getInstance()->getRouter()->assemble(array('module' => 'friendsinviter','controller' => 'help', 'action' => 'index'), 'admin_default') . '?show=6' ),
      'value' => $settings->getSetting('friendsinviter.oauth_yahoo_consumer_key', ''),
    ));
    $this->oauth_yahoo_consumer_key->getDecorator('Description')->setOption('placement', 'append');
    $this->oauth_yahoo_consumer_key->setAttrib('style', 'width:500px');
    $this->oauth_yahoo_consumer_key->getDecorator('Description')->setOption('escape', false);

    $this->addElement('Text', 'oauth_yahoo_consumer_secret', array(
      'label' => 'Yahoo Consumer secret',
      'description' => sprintf( $this->getTranslator()->translate('FRIENDSINVITER_FORM_ADMIN_SERVICE_YCS_DESCRIPTION'), Zend_Controller_Front::getInstance()->getRouter()->assemble(array('module' => 'friendsinviter','controller' => 'help', 'action' => 'index'), 'admin_default') . '?show=6' ),
      'value' => $settings->getSetting('friendsinviter.oauth_yahoo_consumer_secret', '')
    ));
    $this->oauth_yahoo_consumer_secret->getDecorator('Description')->setOption('placement', 'append');
    $this->oauth_yahoo_consumer_secret->setAttrib('style', 'width:500px');
    $this->oauth_yahoo_consumer_secret->getDecorator('Description')->setOption('escape', false);

    $this->addElement('Text', 'oauth_yahoo_app_id', array(
      'label' => 'Yahoo App ID',
      'description' => sprintf( $this->getTranslator()->translate('FRIENDSINVITER_FORM_ADMIN_SERVICE_YAI_DESCRIPTION'), Zend_Controller_Front::getInstance()->getRouter()->assemble(array('module' => 'friendsinviter','controller' => 'help', 'action' => 'index'), 'admin_default') . '?show=6' ),
      'value' => $settings->getSetting('friendsinviter.oauth_yahoo_app_id', '')
    ));
    $this->oauth_yahoo_app_id->getDecorator('Description')->setOption('placement', 'append');
    $this->oauth_yahoo_app_id->setAttrib('style', 'width:500px');
    $this->oauth_yahoo_app_id->getDecorator('Description')->setOption('escape', false);




    $this->addElement('Text', 'oauth_live_client_id', array(
      'label' => 'Live (Hotmail) Client ID',
      'description' => sprintf( $this->getTranslator()->translate('FRIENDSINVITER_FORM_ADMIN_SERVICE_LCID_DESCRIPTION'), Zend_Controller_Front::getInstance()->getRouter()->assemble(array('module' => 'friendsinviter','controller' => 'help', 'action' => 'index'), 'admin_default') . '?show=7' ),
      'value' => $settings->getSetting('friendsinviter.oauth_live_client_id', ''),
    ));
    $this->oauth_live_client_id->getDecorator('Description')->setOption('placement', 'append');
    $this->oauth_live_client_id->setAttrib('style', 'width:500px');
    $this->oauth_live_client_id->getDecorator('Description')->setOption('escape', false);

    $this->addElement('Text', 'oauth_live_client_secret', array(
      'label' => 'Live (Hotmail) Client secret',
      'description' => sprintf( $this->getTranslator()->translate('FRIENDSINVITER_FORM_ADMIN_SERVICE_LS_DESCRIPTION'), Zend_Controller_Front::getInstance()->getRouter()->assemble(array('module' => 'friendsinviter','controller' => 'help', 'action' => 'index'), 'admin_default') . '?show=7' ),
      'value' => $settings->getSetting('friendsinviter.oauth_live_client_secret', '')
    ));
    $this->oauth_live_client_secret->getDecorator('Description')->setOption('placement', 'append');
    $this->oauth_live_client_secret->setAttrib('style', 'width:500px');
    $this->oauth_live_client_secret->getDecorator('Description')->setOption('escape', false);



    // Add submit button
    $this->addElement('Button', 'submit', array(
      'label' => 'Save Changes',
      'type' => 'submit',
      'ignore' => true,
    ));
    
  }
  
  
  public function saveAdminSettings()
  {
    $settings = Engine_Api::_()->getApi('settings', 'core');
    
    $value = $this->getElement('oauth_gmail_client_id')->getValue();
    $settings->setSetting('friendsinviter.oauth_gmail_client_id', $value);

    $value = $this->getElement('oauth_gmail_client_secret')->getValue();
    $settings->setSetting('friendsinviter.oauth_gmail_client_secret', $value);


    $value = $this->getElement('oauth_yahoo_consumer_key')->getValue();
    $settings->setSetting('friendsinviter.oauth_yahoo_consumer_key', $value);
    
    $value = $this->getElement('oauth_yahoo_consumer_secret')->getValue();
    $settings->setSetting('friendsinviter.oauth_yahoo_consumer_secret', $value);
    
    $value = $this->getElement('oauth_yahoo_app_id')->getValue();
    $settings->setSetting('friendsinviter.oauth_yahoo_app_id', $value);


    $value = $this->getElement('oauth_live_client_id')->getValue();
    $settings->setSetting('friendsinviter.oauth_live_client_id', $value);

    $value = $this->getElement('oauth_live_client_secret')->getValue();
    $settings->setSetting('friendsinviter.oauth_live_client_secret', $value);
    

    $this->saved_successfully = true;

  }

  
}